clear
set mem 100m
set more off
use "C:\data\PENDING PROJECTS\VN_Q_A\Data\query_statasets\dataverse_files\apsr_data", clear
log using "C:\data\PENDING PROJECTS\VN_Q_A\Data\query_statasets\dataverse_files\query_apsa_v1.smcl", replace

/*Correlations*/
pwcorr speaknum question crit_per local_per con_per age male degree south party incumbent centralnom fulltime percentage pop_stacked transfer percen_as secondary, star(05)


/*DV1: SPEAKER NUMBER*/

/*H1 Delegates with safe seats speak less*/

xi3: nbreg  speaknum age male degree south  party incumbent centralnom fulltime  , robust cluster(pci_id)
outreg2 using "C:\data\PENDING PROJECTS\VN_Q_A\Data\query_statasets\dataverse_files\speaknum",  bdec(4) tdec(4) e(all) replace

xi3: nbreg  speaknum age male degree south  party incumbent centralnom fulltime percentage, robust cluster(pci_id)
outreg2 using "C:\data\PENDING PROJECTS\VN_Q_A\Data\query_statasets\dataverse_files\speaknum",  bdec(4) tdec(4) e(all) 

/*H4 Transfer Recipients are less likely to complain*/
xi3: nbreg  speaknum age male degree south  party incumbent centralnom fulltime percentage pop transfer percen_as secondary, robust cluster(pci_id)
outreg2 using "C:\data\PENDING PROJECTS\VN_Q_A\Data\query_statasets\dataverse_files\speaknum",  bdec(4) tdec(4) e(all) 

/*H5 Career FE*/
xi3: nbreg speaknum age male degree south  party incumbent centralnom fulltime percentage pop transfer percen_as secondary i.career2, robust cluster(pci_id)
outreg2 using "C:\data\PENDING PROJECTS\VN_Q_A\Data\query_statasets\dataverse_files\speaknum",  bdec(4) tdec(4) e(all)

/*Interaction Fulltime*Cent_Nom*/
xi3: nbreg speaknum age male degree south  party incumbent i.cen*ful percentage  pop transfer percen_as secondary i.career2, robust cluster(pci_id)
outreg2 using "C:\data\PENDING PROJECTS\VN_Q_A\Data\query_statasets\dataverse_files\speaknum",  bdec(4) tdec(4) e(all)

xi3: estsimp nbreg speaknum age male degree south  party incumbent i.cen*ful percentage  pop transfer percen_as secondary i.career2, robust cluster(pci_id)
outreg2 using "C:\data\PENDING PROJECTS\VN_Q_A\Data\query_statasets\dataverse_files\speaknum",  bdec(4) tdec(4) e(all) excel

setx mean
setx  _Icen_1 0 ful 0  _Ice1Xfu 0
simqi
setx  _Icen_1 1 ful 0  _Ice1Xfu 0
simqi
setx  _Icen_1 0 ful 1  _Ice1Xfu 0
simqi
setx  _Icen_1 1 ful 1  _Ice1Xfu 1
simqi

drop  b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12 b13 b14 b15 b16 b17 b18 b19 b20 b21 b22  b23 b24 b25 b26 b27 b28 b29 b30 b31 b32



/****************************************************************************************************************************************************/

/*DV2: Question Count*/

/*H1 Delegates with safe seats speak less*/

xi3: nbreg  question_count age male degree south  party incumbent centralnom fulltime  , robust cluster(pci_id)
outreg2 using "C:\data\PENDING PROJECTS\VN_Q_A\Data\query_statasets\dataverse_files\question_count",  bdec(4) tdec(4) e(all) replace

xi3: nbreg  question_count age male degree south  party incumbent centralnom fulltime percentage, robust cluster(pci_id)
outreg2 using "C:\data\PENDING PROJECTS\VN_Q_A\Data\query_statasets\dataverse_files\question_count",  bdec(4) tdec(4) e(all) 

/*H4 Transfer Recipients are less likely to complain*/
xi3: nbreg  question_count age male degree south  party incumbent centralnom fulltime percentage pop transfer percen_as secondary, robust cluster(pci_id)
outreg2 using "C:\data\PENDING PROJECTS\VN_Q_A\Data\query_statasets\dataverse_files\question_count",  bdec(4) tdec(4) e(all) 

/*H5 Career FE*/
xi3: nbreg  question_count age male degree south  party incumbent centralnom fulltime percentage pop transfer percen_as secondary i.career2, robust cluster(pci_id)
outreg2 using "C:\data\PENDING PROJECTS\VN_Q_A\Data\query_statasets\dataverse_files\question_count",  bdec(4) tdec(4) e(all)

/*Interaction Fulltime*Cent_Nom*/
xi3: nbreg  question_count age male degree south  party incumbent i.cen*ful percentage  pop transfer percen_as secondary i.career2, robust cluster(pci_id)
outreg2 using "C:\data\PENDING PROJECTS\VN_Q_A\Data\query_statasets\dataverse_files\question_count",  bdec(4) tdec(4) e(all)

xi3: estsimp nbreg  question_count age male degree south  party incumbent i.cen*ful percentage  pop transfer percen_as secondary i.career2, robust cluster(pci_id)
outreg2 using "C:\data\PENDING PROJECTS\VN_Q_A\Data\query_statasets\dataverse_files\question_count",  bdec(4) tdec(4) e(all) excel

setx mean
setx  _Icen_1 0 ful 0  _Ice1Xfu 0
simqi
setx  _Icen_1 1 ful 0  _Ice1Xfu 0
simqi
setx  _Icen_1 0 ful 1  _Ice1Xfu 0
simqi
setx  _Icen_1 1 ful 1  _Ice1Xfu 1
simqi

drop  b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12 b13 b14 b15 b16 b17 b18 b19 b20 b21 b22  b23 b24 b25 b26 b27 b28 b29 b30 b31 b32

/*************************************************************************************************************************************************/


/*DV3: Criticize*/

/*H1 Delegates with safe seats speak less*/

xi3: reg ln_crit age male degree south  party incumbent centralnom fulltime  , robust cluster(pci_id)
outreg2 using "C:\data\PENDING PROJECTS\VN_Q_A\Data\query_statasets\dataverse_files\ln_crit",  bdec(4) tdec(4) e(all) replace

xi3: reg ln_crit age male degree south  party incumbent centralnom fulltime percentage, robust cluster(pci_id)
outreg2 using "C:\data\PENDING PROJECTS\VN_Q_A\Data\query_statasets\dataverse_files\ln_crit",  bdec(4) tdec(4) e(all) 

/*H4 Transfer Recipients are less likely to complain*/
xi3: reg ln_crit age male degree south  party incumbent centralnom fulltime percentage pop transfer percen_as secondary, robust cluster(pci_id)
outreg2 using "C:\data\PENDING PROJECTS\VN_Q_A\Data\query_statasets\dataverse_files\ln_crit",  bdec(4) tdec(4) e(all) 

/*H5 Career FE*/
xi3: reg ln_crit age male degree south  party incumbent centralnom fulltime percentage pop transfer percen_as secondary i.vcp, robust cluster(pci_id)
outreg2 using "C:\data\PENDING PROJECTS\VN_Q_A\Data\query_statasets\dataverse_files\ln_crit",  bdec(4) tdec(4) e(all)

/*Interaction Central Nom*Fulltime*/
xi3: reg ln_crit age male degree south  party incumbent i.cen*ful percentage  pop transfer percen_as secondary i.vcp, robust 
outreg2 using "C:\data\PENDING PROJECTS\VN_Q_A\Data\query_statasets\dataverse_files\ln_crit",  bdec(4) tdec(4) e(all) excel

/*Dropping 0 Questions*/
xi3: reg ln_crit age male degree south  party incumbent i.cen*ful percentage  pop transfer percen_as secondary if question_count !=0, robust cluster(pci_id)
outreg2 using "C:\data\PENDING PROJECTS\VN_Q_A\Data\query_statasets\dataverse_files\ln_crit",  bdec(4) tdec(4) e(all)

xi3: estsimp reg ln_crit age male degree south  party incumbent i.cen*ful percentage  pop transfer percen_as secondary i.vcp, robust 
outreg2 using "C:\data\PENDING PROJECTS\VN_Q_A\Data\query_statasets\dataverse_files\ln_crit",  bdec(4) tdec(4) e(all) excel

setx mean
setx  _Icen_1 0 ful 0  _Ice1Xfu 0
simqi
setx  _Icen_1 1 ful 0  _Ice1Xfu 0
simqi
setx  _Icen_1 0 ful 1  _Ice1Xfu 0
simqi
setx  _Icen_1 1 ful 1  _Ice1Xfu 1
simqi

drop  b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12 b13 b14 b15 b16 b17

/********************************************************************************************************************************************/

/*DV4: Local Issues*/

/*H1 Delegates with safe seats speak less*/

xi3: reg ln_local age male degree south  party incumbent centralnom fulltime percentage pop transfer percen_as secondary, robust cluster(pci_id)
outreg2 using "C:\data\PENDING PROJECTS\VN_Q_A\Data\query_statasets\dataverse_files\ln_local",  bdec(4) tdec(4) e(all) replace

/*H5 Career FE*/
xi3: reg ln_local age male degree south  party incumbent centralnom fulltime percentage pop transfer percen_as secondary i.vcp, robust cluster(pci_id)
outreg2 using "C:\data\PENDING PROJECTS\VN_Q_A\Data\query_statasets\dataverse_files\ln_local",  bdec(4) tdec(4) e(all)

/*Interaction Central*Fulltime*/
xi3: reg ln_local age male degree south  party incumbent i.cen*ful percentage  pop transfer percen_as secondary i.vcp, robust cluster(pci_id)
outreg2 using "C:\data\PENDING PROJECTS\VN_Q_A\Data\query_statasets\dataverse_files\ln_local",  bdec(4) tdec(4) e(all) excel

/*Dropping 0 Questions*/
xi3: reg ln_local age male degree south  party incumbent i.cen*ful percentage  pop transfer percen_as secondary if question_count !=0, robust cluster(pci_id)
outreg2 using "C:\data\PENDING PROJECTS\VN_Q_A\Data\query_statasets\dataverse_files\ln_local",  bdec(4) tdec(4) e(all)

xi3: estsimp reg ln_local age male degree south  party incumbent i.cen*ful percentage  pop transfer percen_as secondary i.vcp, robust cluster(pci_id)
outreg2 using "C:\data\PENDING PROJECTS\VN_Q_A\Data\query_statasets\dataverse_files\ln_local",  bdec(4) tdec(4) e(all) excel

setx mean
setx  _Icen_1 0 ful 0  _Ice1Xfu 0
simqi
setx  _Icen_1 1 ful 0  _Ice1Xfu 0
simqi
setx  _Icen_1 0 ful 1  _Ice1Xfu 0
simqi
setx  _Icen_1 1 ful 1  _Ice1Xfu 1
simqi

drop  b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12 b13 b14 b15 b16 b17
/********************************************************************************************************************************************/

/*DV5: Constituency*/

/*H1 Delegates with safe seats speak less*/

xi3: reg ln_con age male degree south  party incumbent centralnom fulltime percentage pop transfer percen_as secondary, robust cluster(pci_id)
outreg2 using "C:\data\PENDING PROJECTS\VN_Q_A\Data\query_statasets\dataverse_files\ln_con",  bdec(4) tdec(4) e(all) replace

/*H5 Career FE*/
xi3: reg ln_con age male degree south  party incumbent centralnom fulltime percentage pop transfer percen_as secondary i.vcp, robust cluster(pci_id)
outreg2 using "C:\data\PENDING PROJECTS\VN_Q_A\Data\query_statasets\dataverse_files\ln_con",  bdec(4) tdec(4) e(all)

/*Interaction Central*Fulltime*/
xi3: reg ln_con age male degree south  party incumbent i.cen*ful percentage  pop transfer percen_as secondary i.vcp, robust cluster(pci_id)
outreg2 using "C:\data\PENDING PROJECTS\VN_Q_A\Data\query_statasets\dataverse_files\ln_con",  bdec(4) tdec(4) e(all) excel

/*Dropping 0 Questions*/
xi3: reg ln_con age male degree south  party incumbent i.cen*ful percentage  pop transfer percen_as secondary if question_count !=0, robust cluster(pci_id)
outreg2 using "C:\data\PENDING PROJECTS\VN_Q_A\Data\query_statasets\dataverse_files\ln_con",  bdec(4) tdec(4) e(all)

xi3: estsimp reg ln_con age male degree south  party incumbent i.cen*ful percentage  pop transfer percen_as secondary i.vcp, robust cluster(pci_id)
outreg2 using "C:\data\PENDING PROJECTS\VN_Q_A\Data\query_statasets\dataverse_files\ln_con",  bdec(4) tdec(4) e(all) excel

setx mean
setx  _Icen_1 0 ful 0  _Ice1Xfu 0
simqi
setx  _Icen_1 1 ful 0  _Ice1Xfu 0
simqi
setx  _Icen_1 0 ful 1  _Ice1Xfu 0
simqi
setx  _Icen_1 1 ful 1  _Ice1Xfu 1
simqi

drop  b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12 b13 b14 b15 b16 b17
/****************************************************************************************************************************************************/

/*JOURNALIST SURVEY*/
#delimit;
clear;
use "C:\data\PENDING PROJECTS\VN_Q_A\Data\query_statasets\dataverse_files\journalists2", clear;

collapse delegate_id  average_crit average_news average_local thuy_question1 thuy_question2 thuy_question3 nhung_question1 nhung_question2 nhung_question3 kien_question1 kien_question2 
kien_question3 cuong_question1 cuong_question2 cuong_question3, by(delegate);
hilo  average_crit delegate;
hilo   average_news delegate;
hilo   average_local delegate;

sort delegate_id;
save "C:\data\PENDING PROJECTS\VN_Q_A\Data\query_statasets\dataverse_files\delegate_journalists", replace;

/*Merge*/
use "C:\data\PENDING PROJECTS\VN_Q_A\Data\query_statasets\dataverse_files\apsr_data", clear;
sort delegate_id;
drop _merge;
merge delegate_id using "C:\data\PENDING PROJECTS\VN_Q_A\Data\query_statasets\dataverse_files\delegate_journalists";
save "C:\data\PENDING PROJECTS\VN_Q_A\Data\query_statasets\dataverse_files\apsr_data_v2.dta", replace;
drop b*;


/************************************************************************************************************************************/
/*Other Robustness*/

pwcorr crit_per  average_crit thuy_question1 nhung_question1 kien_question1 cuong_question1, star(5);
pwcorr local_per  average_local thuy_question2 nhung_question2 kien_question2 cuong_question2, star(5);

generate average_crit0=average_crit;
replace average_crit0=0 if average_crit==.;
generate average_news0=average_news;
replace average_news0=0 if average_news==.;
generate average_local0=average_local;
replace average_local0=0 if average_local==.;

generate any_query=1 if question_count>0;
replace any_query=0 if question_count==0;


pwcorr crit_per  average_crit average_crit0, star(5);
pwcorr local_per  average_local average_local0, star(5);

xi3:  reg  average_crit0 age male degree south  party incumbent i.cen*ful percentage  pop transfer percen_as secondary, robust cluster(pci_id);
xi3:  reg  average_local0 age male degree south  party incumbent i.cen*ful percentage  pop transfer percen_as secondary, robust cluster(pci_id);

reg crit_per  thuy_question1 nhung_question1 kien_question1 cuong_question1, robust cluster(pci_id);
reg local_per  thuy_question3 nhung_question3 kien_question3 cuong_question3, robust cluster(pci_id);

xi3: reg average_crit0 age male degree south  party incumbent centralnom fulltime cenful percentage pop transfer percen_as secondary i.vcp, robust cluster(pci_id);
outreg2 using "C:\data\PENDING PROJECTS\VN_Q_A\Data\query_statasets\dataverse_files\journalists",  bdec(3) tdec(3) e(all);



/*Heckman Two-Stages*/
xi3: heckman ln_crit party incumbent i.cen*ful percentage  pop transfer percen_as secondary i.career2, 
select (any_query =  age male degree south  party incumbent cen ful cenful percentage  pop transfer percen_as secondary i.career2) 
vce(cluster pci_id);
outreg2 using "C:\data\PENDING PROJECTS\VN_Q_A\Data\query_statasets\dataverse_files\heckman",  bdec(3) tdec(3) e(all) replace;



/*Counts*/

xi3: nbreg criticize_total age male degree south  party incumbent centralnom fulltime cenful percentage pop 
transfer percen_as secondary i.vcp, robust cluster(pci_id);
outreg2 using "C:\data\PENDING PROJECTS\VN_Q_A\Data\query_statasets\dataverse_files\nonpercent",  bdec(3) tdec(3) e(all) replace;

xi3: nbreg local_total age male degree south  party incumbent centralnom fulltime cenful percentage pop 
transfer percen_as secondary i.vcp, robust cluster(pci_id);
outreg2 using "C:\data\PENDING PROJECTS\VN_Q_A\Data\query_statasets\dataverse_files\nonpercent",  bdec(3) tdec(3) e(all);

xi3: nbreg cutri_total age male degree south  party incumbent centralnom fulltime cenful percentage pop 
transfer percen_as secondary i.vcp, robust cluster(pci_id);
outreg2 using "C:\data\PENDING PROJECTS\VN_Q_A\Data\query_statasets\dataverse_files\nonpercent",  bdec(3) tdec(3) e(all) excel;


/**************************************************************************************************************/

/*Figures*/
use "C:\data\PENDING PROJECTS\VN_Q_A\Data\query_statasets\dataverse_files\clarify2.dta", clear;

generate exp_low_90= exp_mean-(1.6* exp_se);
generate exp_hi_90= exp_mean+(1.6* exp_se);

twoway (rcap  exp_low_90 exp_hi_90 percentage if percentage >=55 & percentage <=90 & cen==0 & ful==0, msize(medium) lwidth(medthick) lcolor(blue) lpattern(shortdash)) 
(scatter   exp_mean percentage if percentage >=55 & percentage <=90 & cen==0 & ful==0, msymbol(circle) mcolor(blue) msize(medsmall)) 
(rcap  exp_low_90 exp_hi_90 percentage if percentage >=55 & percentage <=90 & cen==0 & ful==1, msize(medium) lwidth(medthin) lcolor(navy)) 
(scatter   exp_mean percentage if percentage >=55 & percentage <=90 & cen==0 & ful==1, msymbol(triangle) mcolor(navy) msize(medsmall)), xlab(55(5)90) 
xtitle("",) legend(off) ytitle("Critical Questions Asked of Ministers (%)", size(medlarge) margin(medium)) title("Local Delegates", size(large));

graph save percentage_local.gph, replace;


twoway (rcap  exp_low_90 exp_hi_90 percentage if percentage >=55 & percentage <=90 & cen==1 & ful==0, msize(medium) lwidth(medthick) lcolor(blue) lpattern(shortdash)) 
(scatter   exp_mean percentage if percentage >=55 & percentage <=90 & cen==1 & ful==0, msymbol(circle) mcolor(blue) msize(medsmall)) 
(rcap  exp_low_90 exp_hi_90 percentage if percentage >=55 & percentage <=90 & cen==1 & ful==1, msize(medium) lwidth(medthin) lcolor(navy)) 
(scatter   exp_mean percentage if percentage >=55 & percentage <=90 & cen==1 & ful==1, msymbol(triangle) mcolor(navy) msize(medsmall)), xlab(55(5)90)   
xtitle("",) 
legend(rows (2) size(small) label (1 "90% CI") label (2 Part-Time) 
label (3 "90% CI") label (4 Fulltime) ring (0) position(12)) 
ytitle("Critical Questions Asked of Ministers (%)", size(medlarge) margin(medium)) title("Central Delegates", size(large));

graph save percentage_central.gph, replace;

graph combine percentage_local.gph percentage_central.gph, xcommon ycommon title("Percentage of Votes Received in 2007 Election", position(6));


use "C:\data\PENDING PROJECTS\VN_Q_A\Data\query_statasets\dataverse_files\career_clarify.dta", clear;


twoway (rcap  low_ques hi_ques  career_code2,  lcolor(navy) mcolor(navy) lwidth(medthin) horizontal msize(medlarge)) 
(scatter  career_code2 mean_ques),  ylabel(1(1)17, labels labsize(medsmall) angle(horizontal) valuelabel)  ytitle("")  
xline(0, lcolor(red) lwidth(medthick) lpattern(dash)) xlab(-5(2)11) title("Total Questions Asked", size(vlarge)) 
legend(off) fxsize(80) xtitle("");

graph save career_question.gph, replace;

twoway (rcap   low_crit hi_crit  career_code2,  lcolor(navy) mcolor(navy) lwidth(medthin) horizontal msize(medlarge)) 
(scatter  career_code2  mean_crit), ylabel(1(1)17, nolabels) ytitle("")  
xline(0, lcolor(red) lwidth(medthick) lpattern(dash)) xlab(-50(30)80) title("Percent Critical", size(vlarge))
legend(off) xtitle("");

graph save career_critical.gph, replace;

graph combine career_question.gph  career_critical.gph, cols(2);

graph save f3_fe, replace;


twoway (rcap  low_local hi_local  career_code2,  lcolor(navy) mcolor(navy) lwidth(medthin) horizontal msize(medlarge))  
(scatter  career_code2  mean_local),  ylabel(1(1)17, labels labsize(medsmall) angle(horizontal) valuelabel)  ytitle("") 
 xline(0, lcolor(red) lwidth(medthick) lpattern(dash)) xlab(-20(5)20) title("Percent Local", size(vlarge)) legend(off)  
fxsize(80) xtitle("");

graph save career_local.gph, replace;


twoway (rcap   low_con hi_con  career_code2,  lcolor(navy) mcolor(navy) lwidth(medthin) horizontal msize(medlarge))  
(scatter  career_code2   mean_con),  ylabel(1(1)17, nolabels) ytitle("")   ytitle("")  
xline(0, lcolor(red) lwidth(medthick) lpattern(dash)) xlab(-20(5)20) title("Cite Constituency (%)", size(vlarge)) legend(off)  xtitle("");

graph save career_con.gph, replace;


graph combine career_local.gph career_con.gph, cols(2) ;

graph save f4_local_fe, replace;

log close;
